package com.zjp.demo02251.utils;

import com.zjp.demo02251.dao.Result;
import com.zjp.demo02251.enums.ResultEnum;

/**
 * @author james
 * @Title: ResultUtil
 * @Package com.zjp.demo02251.utils
 * @Description:
 * @date 2018/2/25  18:50
 */
public class ResultUtil {

  /**
   * @Description: 返回成功的输出格式
   * @author james
   * @date 2018/2/25  18:56
  */
  public static Result success(Object object){
      Result result = new Result();
      result.setCode(1);
      result.setMsg("操作成功");
      result.setData(object);
      return result;
  }

  /**
   * @Description: 不带内容的输出格式
   * @author james
   * @date 2018/2/25  18:57
  */
  public static Result success(){
         return success(null);

  }

  /**
   * @Description: 返回失败输出格式
   * @author james
   * @date 2018/2/25  18:57
  */
  public static Result error(ResultEnum resultEnum){
      Result result = new Result();
      result.setCode(resultEnum.getCode());
      result.setMsg(resultEnum.getMsg());
      result.setData(null);
      return result;
  }


    public static Result error(Integer code,String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return  result;
    }
}
